<?php

namespace App\Http\Controllers\Personal;
use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Style;

/**
 * @param //浏览企业记录
 * 创建时间 2016-8-13
 **/
class browseCompanyController extends CommonController{
    /**
     * 浏览企业记录
     * @param Request $request
     * @return mixed
     */
    public function browseCompany(Request $request){
        $user = auth()->guard('personal')->user();
        //关键词搜索
        $keyword  = trim($request->keyword);
        //获取面试通知记录
        $browse_company = DB::table('browse_company as t1')
            ->join('company_basic as t2', 't1.com_id', '=', 't2.id')
            ->join('company_users as t3', 't1.company_uid', '=', 't3.uid')
            ->select(
                't1.id','t1.created_at','t1.com_id',
                't2.company_name','t2.region','t2.industry','t2.region',
                't3.last_login_time'
            )
            ->where('t1.personal_uid',$user->uid)
            ->where(function ($query) use ($keyword) {
                if(strlen($keyword) > 0){
                    $query->where('t2.company_name','like','%'.$keyword.'%');
                }
            })
            ->orderBy('created_at', 'desc')
            ->paginate(10);
        //处理数组
        foreach($browse_company as $v){
            $v->industry = ($v->industry) ? str_limit(CollOption::getOptionName($v->industry,'industry'),22) : '';
            $v->company_name = str_limit($v->company_name,28);
            $v->region = str_limit(str_replace(',','',CollArea::getCityAddress($v->region)),20);
            $v->created_at = substr($v->created_at,0,10);
            $v->last_login_time = substr($v->last_login_time,0,16);
        }
        //分页分配参数 过滤空值
        $appends =  arrayFilter( array(
            'keyword' => $keyword
        ));
        return Style::view('personal.browseCompany',compact('browse_company','appends'));
    }
}